package com.hliushi.learn.controller;

import com.hliushi.learn.exception.BusinessErrorException;
import com.hliushi.learn.exception.BusinessMsgEnum;
import com.hliushi.learn.response.JsonResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

/**
 * @ClassName ExceptionController
 * @Description TODO
 * @Author hliushi
 * @Date 2021/7/7 8:29
 * @Version V1.0
 **/
@RestController
@RequestMapping("/exception")
public class ExceptionController {

    private static final Logger LOGGER = LoggerFactory.getLogger(ExceptionController.class);

    /**
     * @param
     * @return
     */
    @PostMapping("/test")
    public JsonResult<Void> test(@RequestParam String name, @RequestParam String pass) {

        LOGGER.info("name: {}", name);
        LOGGER.info("pass: {}", pass);

        return new JsonResult<>();
    }

    /**
     * @param
     * @return
     */
    @GetMapping("/business")
    public JsonResult<Void> testException() {
        try {
            int i = 1 / 0;
        } catch (Exception e) {
            throw new BusinessErrorException(BusinessMsgEnum.UNEXCEPTION_EXCEPTION);
        }

        return new JsonResult<>();
    }


    /**
     * 测试 异常
     */
    @GetMapping("/get")
    public String get() {
        int i = 1 / 0;
        return "success";
    }
}
